package com.tbit.api;

import cn.hutool.core.collection.CollectionUtil;
import com.tbit.common.entity.pojo.dto.BarChartDispatchLogDTO;
import com.tbit.common.entity.pojo.dto.BarChartRepairDTO;
import com.tbit.common.entity.pojo.vo.CoreDataVO;
import com.tbit.common.entity.pojo.vo.DateResult;
import com.tbit.common.entity.pojo.vo.LineChartVO;
import com.tbit.manager.api.MaintainOAApi;
import com.tbit.common.entity.view.Result;
import com.tbit.uqbike.service.business.DispatchLogService;
import com.tbit.uqbike.service.business.MoveLogService;
import com.tbit.uqbike.service.business.PowerChangeLogService;
import com.tbit.uqbike.service.business.RepairLogService;
import com.tbit.uqbike.service.business.operationsanalysis.MaintainOAService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 运营分析-运维分许
 *
 * @author <a href="mailto:liu.haoxiang@tbit.com.cn">BUGXiang</a>
 * @version 1.0
 * @since 2025-3-11
 */
@RestController
@Slf4j
public class MaintainOAApiImpl implements MaintainOAApi {

    @Resource
    private MaintainOAService maintainOAService;
    @Resource
    private PowerChangeLogService powerChangeLogService;
    @Resource
    private MoveLogService moveLogService;
    @Resource
    private DispatchLogService dispatchLogService;
    @Resource
    private RepairLogService repairLogService;


    /**
     * 获取运营分析-运维分析数据核心数据
     *
     * @param accountId 区域id
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @return CoreDataVO
     */
    @Override
    public CoreDataVO getMainCoreData(Integer accountId, Date startDate, Date endDate) {
        Result<CoreDataVO> mainCoreData = maintainOAService.getMainCoreData(accountId, startDate, endDate);
        return mainCoreData.getData();
    }


    /**
     * 获取运营分析-运维分析数据-用户故障反馈数折线图
     *
     * @param accountId 区域id
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @return List<LineChartVO>
     */
    @Override
    public List<LineChartVO> getMachineFaultLineChart(Integer accountId, Date startDate, Date endDate) {
        Result<List<LineChartVO>> machineFaultLineChart = maintainOAService.getMachineFaultLineChart(accountId, startDate, endDate);
        return machineFaultLineChart.getData();
    }


    /**
     * 运营分析-运维分析数据-车辆数据分时折线图
     *
     * @param accountId 区域id
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @param type      数据类型：1-低电分时 2-超区分时 3-超时分时
     * @return List<LineChartVO>
     */
    @Override
    public List<LineChartVO> getMachineLineChart(Integer accountId, Date startDate, Date endDate, Integer type) {
        Result<List<LineChartVO>> machineLineChart = maintainOAService.getMachineLineChart(accountId, startDate, endDate, type);
        return machineLineChart.getData();
    }


    /**
     * 运营分析-运维分析数据-换电折线图
     *
     * @param accountId 区域id
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @return List<DateResult>
     */
    @Override
    public List<DateResult> getPowerChangeLineChart(Integer accountId, Date startDate, Date endDate) {
        List<DateResult> data = maintainOAService.getPowerAnalyze(accountId, startDate, endDate).getData();
        return CollectionUtil.isEmpty(data) ? new ArrayList<>() : data;
    }


    /**
     * 运营分析-运维分析数据-挪车折线图
     *
     * @param accountId 区域id
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @return List<DateResult>
     */
    @Override
    public List<DateResult> getMoveLineChart(Integer accountId, Date startDate, Date endDate) {
        List<DateResult> data = maintainOAService.getMoveAnalyze(accountId, startDate, endDate).getData();
        return CollectionUtil.isEmpty(data) ? new ArrayList<>() : data;
    }

    /**
     * 运营分析-运维分析数据-调度折线图
     *
     * @param accountId 区域id
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @return List<DateResult>
     */
    @Override
    public List<DateResult> getDispatchLineChart(Integer accountId, Date startDate, Date endDate) {
        List<DateResult> data = maintainOAService.getDispatchAnalyze(accountId, startDate, endDate).getData();
        return CollectionUtil.isEmpty(data) ? new ArrayList<>() : data;
    }


    /**
     * 运营分析-运维分析数据-维修折线图
     *
     * @param accountId 区域id
     * @param startDate 开始时间
     * @param endDate   结束时间
     * @return List<DateResult>
     */
    @Override
    public List<DateResult> getRepairLineChart(Integer accountId, Date startDate, Date endDate) {
        List<DateResult> data = maintainOAService.getRepairAnalyze(accountId, startDate, endDate).getData();
        return CollectionUtil.isEmpty(data) ? new ArrayList<>() : data;
    }


}
